package weixin_oauth

import (
	"fmt"
	"log/slog"
	"net/url"
)

// Authorize 重定向链接
func Authorize(appid, redirectUri, scope, state string) string {
	if scope == "" {
		scope = "snsapi_base"
	}
	authorizeUrl := fmt.Sprintf(
		"https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect",
		appid,
		url.QueryEscape(redirectUri),
		scope,
		state)
	slog.Info("Authorize URL " + authorizeUrl)
	return authorizeUrl
}
